import { Collection, EntitySchema } from '@mikro-orm/core';
import { OfficeNewsSendRecords } from './OfficeNewsSendRecords';
import { OfficePosts } from './OfficePosts';

export class OfficeNews {
  id!: string;
  articleId?: unknown;
  updatedAt?: Date;
  createdAt?: Date;
  creatorId?: string;
  removedAt?: Date;
  postsPivots = new Collection<OfficePosts>(this);
  records = new Collection<OfficeNewsSendRecords>(this);
}

export const OfficeNewsSchema = new EntitySchema({
  class: OfficeNews,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    articleId: { type: 'unknown', columnType: 'char(64)', nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
    createdAt: { type: 'Date', length: 0, nullable: true },
    creatorId: { type: 'string', columnType: 'bigint', nullable: true },
    removedAt: { type: 'Date', length: 0, nullable: true },
    postsPivots: {
      reference: 'm:n',
      entity: () => OfficePosts,
      joinColumn: 'news_id',
      inverseJoinColumn: 'post_id',
    },
    records: { reference: '1:m', entity: () => OfficeNewsSendRecords, mappedBy: 'news' },
  },
});
